package com.pwt.service;

import com.pwt.entity.AcceptanceHand;
import com.pwt.repository.AcceptanceHandRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * AcceptanceHand service层
 *
 * @author auto generated
 * @date 2021-09-29 14:52:53
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class AcceptanceHandService {

    private AcceptanceHandRepository acceptanceHandRepository;

    public AcceptanceHandService(AcceptanceHandRepository acceptanceHandRepository) {
        this.acceptanceHandRepository = acceptanceHandRepository;
    }


    public AcceptanceHand  setting(AcceptanceHand acceptance){
        AcceptanceHand acceptanceHand = this.acceptanceHandRepository.getAcceptanceHandByTeilAndMerkmal(acceptance.getTeil(),acceptance.getMerkmal());
        if(acceptanceHand == null){
            acceptanceHand = new AcceptanceHand();
            acceptanceHand.setTeil(acceptance.getTeil());
            acceptanceHand.setMerkmal(acceptance.getMerkmal());
        }
        acceptanceHand.setMeugw(acceptance.getMeugw());
        acceptanceHand.setMeogw(acceptance.getMeogw());
        return this.acceptanceHandRepository.save(acceptanceHand);
    }

}
